<?php
/*------------------------------------------------------------------------------
this file is part of Web Application Kit http://webappkit.net
Copyright (C) 2006 J.Ducastel <jducastel@jducastel.fr>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
------------------------------------------------------------------------------*/

/**
* template store > 
* files implementation
* @author J.Ducastel <jducastel@jducastel.fr>
* @version 
*/
class wakTemplateStore {
/*------------------------------------------------------------------------------
                                                                     constructor
------------------------------------------------------------------------------*/
	/**
	*
	* @access
	*/
	function wakTemplateStore() {
		$this->__construct();
	}/**/
	
	/**
	* "real" constructor
	* @access
	*/
	function __construct() {
		//parent::__construct();
		// getting required libraries
		$lib=&wak::getservice('waklib');
		$lib->needClass('foldernode');
		$lib->needClass('filenode');
		$lib->needClass('waktemplate');
	}/**/
/*------------------------------------------------------------------------------
                                                                  public methods
------------------------------------------------------------------------------*/
	/**
	* get instance by id
	* @param
	* @access public
	* @return 
	*/
	function & getById($id) {
		// searching for file
		if (!$this->folderNode) {
			$r=false;
			return $r;
		}
		$regex="^($id)\.([a-zA-Z_-]+)\.tpl\$";
		if (!$results=$this->folderNode->regexSearchName($regex,true))
			return false;
		$fileNode=&$results[0];
		$content=$fileNode->read();
		// searching for engine type
		$search=$fileNode->regexSelfName($regex);
		$engine=isset($search[2])?$search[2]:null;
		// building template
		$tpl=&new wakTemplate();
		$tpl->setId($id);
		$tpl->setEngine($engine);
		$tpl->setContent($content);
		return $tpl;
	}/**/
	
	/**
	* sets store location (folder)
	* @param string $location
	* @access public
	* @return bool
	*/
	function setLocation($location) {
		if (!$folderNode=pathnode::getnode($location)
		or !is_a($folderNode,'foldernode'))
			return false;
		$this->location=$location;
		$this->folderNode=&$folderNode;
		return true;
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access public
	* @return 
	* /
	function () {
		
	}/**/
/*------------------------------------------------------------------------------
                                                                      properties
------------------------------------------------------------------------------*/
	/**
	* @var foldernode foldernode instance for file retrieving
	*/
	var $folderNode;
	
/*------------------------------------------------------------------------------
                                                               protected methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access protected
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access protected
	* @return 
	* /
	function () {
		
	}/**/
	
/*------------------------------------------------------------------------------
                                                                 private methods
------------------------------------------------------------------------------*/
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
	
	/**
	* 
	* @param
	* @access private
	* @return 
	* /
	function () {
		
	}/**/
}
?>
